/*
 * 122.cpp
 * Copyright (C) 2015 libo <libo@tencent.com>
 *
 * Distributed under terms of the MIT license.
 */

#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <queue>

using namespace std;


struct node_t {
  int value;
  bool have_value;
  node_t *left, *right;
  node_t() { value = 0; have_value = false;
    left = NULL; right = NULL; };
};

node_t* new_node() {
  return new node_t();
};

node_t* root = new_node();   
queue<node_t*> bfs_q;

int build_tree(int value, const char* pos) {
  const char* idx = pos;
  node_t* tmp = root;
  while (*idx != ')') {
    if (*idx == 'L') {
      if (tmp->left == NULL)
        tmp->left = new_node();
      tmp = tmp->left;
    } else if (*idx == 'R') {
      if (tmp->right == NULL)
        tmp->right = new_node();
      tmp = tmp->right;
    } 
    ++idx;
  }
  if (tmp->have_value) return -1;
  tmp->value = value;
  tmp->have_value = true;
  return 0;
};

void bfs(node_t* root) {
  while(bfs_q.size() > 0) {
    node_t* one_node = bfs_q.front();
    bfs_q.pop();
    if (!one_node->have_value) return;
    cout << one_node->value << " ";
    if (one_node->left) bfs_q.push(one_node->left);
    if (one_node->right) bfs_q.push(one_node->right);
  }
};

void free_node(node_t* node) {
  if (node == NULL) return;
  if (node->left) free_node(node->left);
  if (node->right) free_node(node->right);
  delete node;
};

int main() {
  const int maxn = 1024;
  char s[maxn];
  for (;;) {
    scanf("%s", s);
    if (strcmp(s, "()") == 0) break;
    int value;
    sscanf(&s[1], "%d", &value);
    assert(build_tree(value, strchr(s, ',') + 1) == 0);
  }
  bfs_q.push(root);
  bfs(root);
  free_node(root);
  return 0;
}
